﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

namespace Web.Admin
{
    public partial class Article : BaseCode.BaseAdmin
    {
        private DAL_Article dalArticle = new DAL_Article();

        protected void Page_Load(object sender, EventArgs e)
        {
            this.AspNetPager1.PageSize = 10;     //设置每也显示的记录条数 
            if (!IsPostBack)
            {
                bind();
            }
        }
        public void bind()
        {
            string strwhere = "1=1";

            AspNetPager1.RecordCount = dalArticle.GetArticleListCnt(strwhere);       //获得要使用表的记录总数 
            DataTable list = dalArticle.GetArticleData(this.AspNetPager1.PageSize,
                                                           this.AspNetPager1.CurrentPageIndex, strwhere);
            Repeater1.DataSource = list;
            this.Repeater1.DataBind();

            this.Label1.Text = "当前第" + this.AspNetPager1.CurrentPageIndex + "页 总" + this.AspNetPager1.PageCount + "页";
        }
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "remove")
            {
                string strid = e.CommandArgument.ToString();
                if (dalArticle.DeleteArticle(int.Parse(strid)))
                {
                    Response.Write("<script type='text/javascript'>alert('删除成功！');</script>");
                    bind();
                }
                else
                {
                    Response.Write("<script type='text/javascript'>alert('删除失败！');</script>");
                    return;
                }
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            this.bind();
        }
    }
}